Skip to content

Support retry handling when calling activity/suborchestrations#77

Merged
YunchuWang merged 5 commits intomainfrom
wangbill/retry
Jan 31, 2026
Merged

Support retry handling when calling activity/suborchestrations#77
YunchuWang merged 5 commits intomainfrom
wangbill/retry

Conversation

@YunchuWang
Copy link
Copy Markdown
Member

This pull request adds support for configurable retry policies for activities and sub-orchestrations in the Durable Task JS SDK. It introduces new types and options for specifying retry behavior, implements the core retry logic, and refactors orchestration context methods to accept these new options. The changes are organized into three main themes: retry policy implementation, orchestration context API updates, and integration with the orchestration executor.

Retry policy implementation:

  • Added the RetryPolicy class and RetryPolicyOptions interface in retry-policy.ts, allowing users to specify max attempts, backoff, max interval, and timeout for retries. Includes validation and documentation.
  • Introduced the RetryableTask class to track retry attempts, failures, and compute the next retry delay using exponential backoff.
  • Added the RetryTimerTask class to represent timer tasks associated with retryable tasks, enabling precise retry scheduling.

Orchestration context API updates:

  • Updated OrchestrationContext methods (callActivity and callSubOrchestrator) to accept new TaskOptions and SubOrchestrationOptions parameters, allowing users to configure retry policies and instance IDs for sub-orchestrations.
  • Added utility functions (taskOptionsFromRetryPolicy, subOrchestrationOptionsFromRetryPolicy) and option types in task-options.ts for easier creation of options from retry policies.

Integration with orchestration executor:

  • Refactored the orchestration executor to recognize and handle RetryTimerTask instances, rescheduling the original retryable task when a retry timer fires.
  • Updated exports and imports throughout the codebase to expose the new retry-related types and options. [1] [2] [3] [4] [5]

These changes enable robust, configurable retries for activities and sub-orchestrations, improving reliability and developer control over task execution in orchestrations.

delete old task when scheduling retries
@YunchuWang YunchuWang marked this pull request as ready for review January 30, 2026 19:24
Copilot AI review requested due to automatic review settings January 30, 2026 19:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces configurable retry policies for activities and sub-orchestrations in the Durable Task JS SDK, and wires them through the orchestration context and executor. It also adds unit and end-to-end tests to validate retry behavior (including exponential backoff and exhaustion of attempts) and ensures basic backward compatibility for callActivity without retry options.

Changes:

  • Add RetryPolicy/RetryPolicyOptions, RetryableTask, and RetryTimerTask types plus simple TaskOptions/SubOrchestrationOptions helpers to model retryable orchestrator work and timers.
  • Extend OrchestrationContext and RuntimeOrchestrationContext to accept options on callActivity/callSubOrchestrator, create retryable tasks and retry timers, and reschedule work when retry timers fire.
  • Update the orchestration executor to interpret RetryTimerTasks on timer-fired events, drive retry attempts for activities and sub-orchestrations, and add comprehensive unit and E2E tests to validate the retry pipeline end-to-end.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/e2e-azuremanaged/orchestration.spec.ts Adds E2E coverage verifying activity and sub-orchestration retry behavior, exponential backoff, retry exhaustion, and backward compatibility when no retry policy is provided.
packages/durabletask-js/test/retryable-task.spec.ts Adds unit tests for RetryableTask covering initial state, exponential backoff, max interval capping, timeout handling, attempt counting, failure recording, and task-type handling.
packages/durabletask-js/test/retry-policy.spec.ts Adds unit tests for RetryPolicy construction, defaults, and validation of invalid option combinations.
packages/durabletask-js/test/orchestration_executor.spec.ts Adds executor-level tests that simulate history to verify scheduling of retry timers, rescheduling of activities after timer fire, and orchestration completion/failure after retries.
packages/durabletask-js/src/worker/runtime-orchestration-context.ts Wires TaskOptions/SubOrchestrationOptions into callActivity/callSubOrchestrator, instantiates RetryableTasks, and introduces createRetryTimer/rescheduleRetryableTask to support retry scheduling.
packages/durabletask-js/src/worker/orchestration-executor.ts Integrates retry handling into the executor by recognizing RetryTimerTasks on timer-fired events and driving RetryableTask retry cycles on task-failed/sub-orchestration-failed events.
packages/durabletask-js/src/task/retryable-task.ts Implements RetryableTask, which tracks attempts, stores last failure details, computes next retry delay using a RetryPolicy, and customizes failure behavior.
packages/durabletask-js/src/task/retry/retry-policy.ts Introduces the RetryPolicy class and RetryPolicyOptions interface, with validation and defaults for attempts, backoff, max interval, and retry timeout.
packages/durabletask-js/src/task/retry/index.ts Exports RetryPolicy and RetryPolicyOptions from the retry module for internal and public consumption.
packages/durabletask-js/src/task/retry-timer-task.ts Adds RetryTimerTask, a CompletableTask wrapper that links a timer to its parent RetryableTask for rescheduling.
packages/durabletask-js/src/task/options/task-options.ts Defines TaskOptions and SubOrchestrationOptions (including retry and instance ID) and helper creators to derive them from a RetryPolicy.
packages/durabletask-js/src/task/options/index.ts Re-exports task option types and helper functions as part of the task options module.
packages/durabletask-js/src/task/context/orchestration-context.ts Updates the abstract OrchestrationContext API and documentation for callActivity/callSubOrchestrator to accept the new options types.
packages/durabletask-js/src/index.ts Exposes RetryPolicy, RetryPolicyOptions, and the task option types/helpers from the package root so SDK consumers can configure retries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/durabletask-js/src/worker/runtime-orchestration-context.ts
Comment thread packages/durabletask-js/src/task/retryable-task.ts Outdated
Comment thread packages/durabletask-js/src/task/context/orchestration-context.ts
@YunchuWang YunchuWang merged commit a7676fe into main Jan 31, 2026
7 checks passed
@YunchuWang YunchuWang deleted the wangbill/retry branch January 31, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants